﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FL.DBModule;
using FL.Lite;
/*
 实体类名称：t_sys_lib
 
 
 */

namespace FL.DBModule.Sys
{
    [Serializable]
    [Table("t_sys_user_password_history", "id")]
    public class t_sys_user_password_history : BaseEntity
    {
        [Column]
        public Guid id
        { get; set; }

        [Column]
        public Guid user_id
        { get; set; }

        [Column]
        public string username
        {
            get;
            set;
        }

    
        [Column]
        public string password
        {
            get;
            set;
        }

      
        [Column]
        public DateTime? chang_date
        {
            get;
            set;
        }
    }
    


    [Serializable]
    [Table("t_sys_user", "id")]
    public class SysUser : BaseEntity
    {
        [Column]
        public Guid id
        { get; set; }

        [Column]
        public string username
        {
            get;
            set;
        }

         [Column]
        public Guid? employee_id
        {
            get;
            set;
        }

        [Column]
        public string name
        {
            get;
            set;
        }

        [Column]
        public string password
        {
            get;
            set;
        }

        [Column]
        public string customer_no
        {
            get;
            set;
        }


        [Column]
        public int user_type
        {
            get;
            set;
        }


        [Column]
        public DateTime? effect_date
        {
            get;
            set;
        }

        [Column]
        public DateTime? expire_date
        {
            get;
            set;
        }

        [Column]
        public int status
        {
            get;
            set;
        }



        [Column]
        public Guid add_user
        {
            get;
            set;
        }
        [Column]
        public DateTime add_time
        {
            get;
            set;
        }



        /// <summary>
        /// 部门辅助码
        /// </summary>
        public string dept_help_code
        {
            get
            {
                try
                {
                    string strSql = string.Format(@"select  c.help_code from t_base_employee 
a inner join t_sys_user b on a.id= b.employee_id
left join  t_base_department c on c.id= a.dept_id
where b.username='{0}'", this.username);
                    DAL.DbSql db = new DAL.DbSql();
                    System.Data.DataTable dt = db.ExecuteQuery(strSql);
                    return dt.Rows[0].ItemArray[0].ToString();
                }
                catch (Exception ex)
                {
                    return "";
                }
            }
        }

        /// <summary>
        /// 客户系统对用的用户所在的客户名称
        /// </summary>
        public string CurrentUserCustomerName
        {
            get
            {
                try
                {
                    string res = string.Empty;
                    if (!string.IsNullOrEmpty(this.customer_no))
                    {
                        string strSql = string.Format(@"select short from t_base_objs as a where a.zucode = '{0}' and zclass_id=100 and stop_yn=0", this.customer_no);
                        DAL.DbSql db = new DAL.DbSql();
                        System.Data.DataTable dt = db.ExecuteQuery(strSql);
                        res = dt.Rows[0].ItemArray[0].ToString();
                    }
                    
                    return res;
                }
                catch (Exception ex)
                {
                    return "";
                }
            }
        }



    }




}
